{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# IJulia rocks! So does Plotly. Check it out\n",
    "\n",
    "using Plotly\n",
    "api_key = \"\" # visit https://plot.ly/api to generate an API username and password\n",
    "username = \"\"\n",
    "\n",
    "Plotly.signin(username, api_key)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<iframe height='750' id='igraph' scrolling='no' seamless='seamless' src='http://plot.ly/~bpostlethwaiteb/24/700/700' width='750'></iframe>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Following data taken from http://julialang.org/ frontpage \n",
    "benchmarks = [\"fib\", \"parse_int\", \"quicksort3\", \"mandel\", \"pi_sum\", \"rand_mat_stat\", \"rand_mat_mul\"]\n",
    "platforms = [\"Fortran\", \"Julia\", \"Python\", \"R\", \"Matlab\", \"Mathematica\", \"Javascript\", \"Go\"]\n",
    "\n",
    "data = {\n",
    "        platforms[1] => [0.26, 5.03, 1.11, 0.86, 0.80, 0.64, 0.96],\n",
    "        platforms[2] => [0.91, 1.60, 1.14, 0.85, 1.00, 1.66, 1.01],\n",
    "        platforms[3] => [30.37, 13.95, 31.98, 14.19, 16.33, 13.52, 3.41 ],\n",
    "        platforms[4] => [411.36, 59.40, 524.29, 106.97, 15.42, 10.84, 3.98  ],\n",
    "        platforms[5] => [1992.00, 1463.16, 101.84, 64.58, 1.29, 6.61, 1.10   ],\n",
    "        platforms[6] => [64.46, 29.54, 35.74, 6.07, 1.32, 4.52, 1.16 ],\n",
    "        platforms[7] => [2.18, 2.43, 3.51, 3.49, 0.84, 3.28, 14.60],\n",
    "        platforms[8] => [1.03, 4.79, 1.25, 2.36, 1.41, 8.12, 8.51]\n",
    "        }\n",
    "\n",
    "pdata = [ {\"x\"=>benchmarks,\"y\"=>data[k],\"bardir\"=>\"h\",\"type\"=>\"bar\",\"name\"=>k} for k = platforms ]\n",
    "\n",
    "layout = {\n",
    "          \"title\"=> \"Julia benchmark comparison (smaller is better, C performance = 1.0)\",\n",
    "          \"barmode\"=> \"group\",\n",
    "          \"autosize\"=> false,\n",
    "          \"width\"=> 900,\n",
    "          \"height\"=> 900,\n",
    "          \"titlefont\"=>\n",
    "          {\n",
    "           \"family\"=> \"Open Sans\",\n",
    "           \"size\"=> 18,\n",
    "           \"color\"=> \"rgb(84, 39, 143)\"\n",
    "           },\n",
    "          \"margin\"=> {\"l\"=>160, \"pad\"=>0},\n",
    "          \"xaxis\"=> {\n",
    "                     \"title\"=> \"Benchmark log-time\",\n",
    "                     \"type\"=> \"log\"\n",
    "                     },\n",
    "          \"yaxis\"=> {\"title\"=> \"Benchmark Name\"}\n",
    "          }\n",
    "\n",
    "response = Plotly.plot(pdata,[\"layout\"=>layout])\n",
    "\n",
    "# Embed in an iframe within IJulia\n",
    "s = string(\"<iframe height='750' id='igraph' scrolling='no' seamless='seamless' src='\",\n",
    "            response[\"url\"],\n",
    "            \"/700/700' width='750'></iframe>\")\n",
    "display(\"text/html\", s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<iframe height='750' id='igraph' scrolling='no' seamless='seamless' src='http://plot.ly/~bpostlethwaiteb/26/700/700' width='750'></iframe>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# checkout https://plot.ly/api/ for more Julia examples!\n",
    "# But to show off some other Plotly features:\n",
    "x = 1:1500\n",
    "y1 = sin(2*pi*x/1500.) + rand(1500)-0.5\n",
    "y2 = sin(2*pi*x/1500.)\n",
    "\n",
    "fish = {\"x\"=>x,\"y\"=> y1,\n",
    "\t\"type\"=>\"scatter\",\"mode\"=>\"markers\",\n",
    "\t\"marker\"=>{\"color\"=>\"rgb(0, 0, 255)\",\"opacity\"=>0.5 } }\n",
    "\n",
    "fit = {\"x\"=> x,\"y\"=> y2,\n",
    "\t\"type\"=>\"scatter\", \"mode\"=>\"markers\", \"opacity\"=>0.8,\n",
    "\t\"marker\"=>{\"color\"=>\"rgb(255, 0, 0)\"} }\n",
    "\n",
    "layout = {\"autosize\"=> false,\n",
    "    \"width\"=> 650, \"height\"=> 550,\n",
    "    \"title\"=>\"Fish School\",\n",
    "\t\"xaxis\"=>{ \"ticks\"=> \"\",\n",
    "        \"gridcolor\"=> \"white\",\n",
    "        \"zerolinecolor\"=> \"white\",    \n",
    "        \"linecolor\"=> \"white\",\n",
    "        \"autorange\"=> false,\n",
    "        \"range\"=>[0,1500] },\n",
    "\t\"yaxis\"=>{ \"ticks\"=> \"\",\n",
    "        \"gridcolor\"=> \"white\",\n",
    "        \"zerolinecolor\"=> \"white\",\n",
    "\t\t\"linecolor\"=> \"white\",\n",
    "        \"autorange\"=> false,\n",
    "        \"range\"=>[-2.2,2.2] },\n",
    "\t\"plot_bgcolor\"=> \"rgb(245,245,247)\",\n",
    "    \"showlegend\"=> false,\n",
    "    \"hovermode\"=> \"closest\"}\n",
    "\n",
    "response = Plotly.plot([fish, fit],[\"layout\"=>layout])\n",
    "s = string(\"<iframe height='750' id='igraph' scrolling='no' seamless='seamless' src='\",\n",
    "            response[\"url\"],\n",
    "            \"/700/700' width='750'></iframe>\")\n",
    "display(\"text/html\", s)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Julia 1.1.1",
   "language": "julia",
   "name": "julia-1.1"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "1.1.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
